package com.acyouzi.leetcode.binarysearch;

import java.util.ArrayList;
import java.util.List;

/**
 * 17/9/13 22:37
 *
 * @author sunxu
 */
public class TwoSumSBT {
  public boolean findTarget(TreeNode root, int k) {
    List<Integer> list = new ArrayList<>();
    helper(list,root);
    int start = 0;
    int end = list.size()-1;
    while (start < end){
      if (list.get(start) + list.get(end) == k) return true;
      else {
        if (list.get(start) + list.get(end) > k) end --;
        if (list.get(start) + list.get(end) < k) start ++;
      }
    }
    return false;
  }
  public void helper( List<Integer> list, TreeNode node){
    if (node == null) return;
    helper(list,node.left);
    list.add(node.val);
    helper(list,node.right);
  }
}
